package com.acme.bankapp.network;

import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.Client;
import com.acme.bankapp.domain.client.ClientFactory;
import com.acme.bankapp.util.FeedFileLineParser;
import com.acme.bankapp.util.ParseException;
import com.acme.bankapp.util.Utils;

/**
 * This class represents client-server communication protocol
 * 
 * @author Anton Kotov
 * 
 */
public class BankReport {

    public BankReport(final Bank bank) {
	this.bank = bank;
    }
    
    public Command processInput(final String message) {
	if (message.startsWith("add ")) {
	    String line = message.substring(4);
	    FeedFileLineParser feedFileLineParser;
	    try {
		feedFileLineParser = new FeedFileLineParser(line);
	    } catch (ParseException e) {
		return new BadCommand(Utils.getErrorMessage(e));
	    }
	    Client client = ClientFactory.createClient(feedFileLineParser);
	    return new AddClientCommand(bank, client);
	}
	
	return new BadCommand("Unknown command");
    }
    
    private Bank bank;
}
